home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9861 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1021 b 

  1. Path: info-server.bbn.com!ahsiung
  2. From: ahsiung@bbn.com (Anita Hsiung)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Checking for Ilegal Input
  5. Date: 12 Mar 1996 16:41:14 GMT
  6. Organization: Bolt Beranek and Newman (BBN)
  7. Sender: ahsiung@bbn.com
  8. Message-ID: <4i49fa$819@info-server.bbn.com>
  9. References: <313855C7.5E86@aol.com>
  10. NNTP-Posting-Host: snap.bbn.com
  11.  
  12. gregace@aol.com writes:
  13. >
  14. >I used the scanf("%d",&number) to read the input.
  15. >
  16. >I check the illegal input by
  17. >
  18. >while (number<0 or number>15)
  19. >{ Printf("Enter a again:");
  20. >  scanf("%d",&number);
  21. >}
  22.  
  23. Why not try:
  24.  
  25. char   *resp;  /* do some memory allocation */
  26. while ( (resp < '0') || (resp > '15') ) {
  27.   printf("Enter a again:");
  28.   scanf("%s", &resp);
  29. }
  30.  
  31. and then do whatever atoi's you want.
  32.  
  33. -- Anita --
  34. -- 
  35. --------->>  Anita Hsiung, Technical Consultant <<---------------
  36. |      BBN Domain Corporation       |    Data Analysis Suite    |
  37. |  Cambridge, Massachusetts, USA    |      ahsiung@bbn.com      |
  38. | "Software Smart, Process Perfect" | 617-873-2854/492-6854 FAX |
  39.